class ContactService

  def self.query_contacts_by_companies_id(companies_id)
    contacts = Contact.where('companies_id': companies_id)
    # TODO 掩码处理
    {
      data: contacts.map{ |item| 
        {
          name: item.name,
          gender: item.gender,
          dept_name: item.dept_name,
          important_level: item.important_level,
          tel_no: MaskUtil.mask_tel_no(item.tel_no), # 暂时没有关联contact_ext表查询所有手机号
          phone_no: item.phone_no,
          email: MaskUtil.mask_email(item.email),
          note: item.note
        } }
    }
  end

  # 添加联系人
  def self.add(json)
    logger = LogUtil.new(path: "log/trevor-exam-api.log")
    logger.info('ContactService#add', "params json=#{ json }")
    !Contact.create(
        companies_id: json[:companies_id],
        name: json[:name],
        tel_no: json[:tel_no],
        gender: json[:gender],
        dept_name: json[:dept_name],
        important_level: json[:important_level],
        phone_no: json[:phone_no],
        email: json[:email],
        note: json[:note]
    ).new_record?
  end

end